/**
 * Created with CLion.
 * Description:
 * User: loong
 * Date: 2024/3/12
 * Time: 8:35
 */

#ifndef CES_ICONTEXT_H
#define CES_ICONTEXT_H
#include "IService.h"

namespace CES::Core {
    class IContext {
    public:
        virtual ~IContext() = default;

        virtual void RegistryService(const QString &_serviceId, IServiceSPtr _service) = 0;

        virtual void UnRegistryService(const QString &_serviceId) = 0;

        virtual IServiceSPtr GetService(const QString &_serviceId) = 0;
    };

    using IContextSPtr = std::shared_ptr<IContext>;
    using IContextWPtr = std::weak_ptr<IContext>;

    template<typename ServiceType, typename ServiceIdType, typename ContextType>
    std::shared_ptr<ServiceType> ServiceByPlugin(ServiceIdType service_id, ContextType context_ptr) {
        return std::dynamic_pointer_cast<ServiceType, IService>(context_ptr->GetService(service_id));
    }
} // namespace CES::Core


#endif//CES_ICONTEXT_H
